<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
ka-Map Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="scalebar.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b>ka-Map</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>scalebar.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		No overview generated for 'scalebar.js'<BR/><BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="ScaleBar.html">ScaleBar</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/*
JavaScript Scalebar for MapServer (scalebar.js)

Copyright (c) 2005 Tim Schaub of CommEn Space (http://www.commenspace.org)

This is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.

This software is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this software; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

v1.3.1 - removed a typo that affected .sbBar with borders (thanks jlivni)
       - scalebar is now centered on .sbWrapper div by default, more css control
       - reduced likelihood of displaying very large numbers
       - added condition to deal with <span class="attrib">@import</span> styles (thanks dokai)

*/</span>

<span class="reserved">function</span> ScaleBar(scaleDenominator) {
    <span class="comment">// default properties</span>
    <span class="comment">// may be modified after construction</span>
    <span class="comment">// if modified after ScaleBar.place(), use ScaleBar.update()</span>
    <span class="reserved">this</span>.scaleDenominator = (scaleDenominator == null) ? 1 : scaleDenominator;
    <span class="reserved">this</span>.displaySystem = <span class="literal">'metric'</span>; <span class="comment">// metric or english supported</span>
    <span class="reserved">this</span>.minWidth = 100; <span class="comment">// pixels</span>
    <span class="reserved">this</span>.maxWidth = 200; <span class="comment">// pixels</span>
    <span class="reserved">this</span>.divisions = 2;
    <span class="reserved">this</span>.subdivisions = 2;
    <span class="reserved">this</span>.showMinorMeasures = false;
    <span class="reserved">this</span>.abbreviateLabel = false;
    <span class="reserved">this</span>.singleLine = false;
    <span class="reserved">this</span>.resolution = 72; <span class="comment">// dpi</span>
    <span class="reserved">this</span>.align = <span class="literal">'center'</span>; <span class="comment">// left, center, or right supported</span>
    <span class="comment">// create scalebar elements</span>
    <span class="reserved">this</span>.container = document.createElement(<span class="literal">'div'</span>);
    <span class="reserved">this</span>.container.className = <span class="literal">'sbWrapper'</span>;
    <span class="reserved">this</span>.labelContainer = document.createElement(<span class="literal">'div'</span>);
    <span class="reserved">this</span>.labelContainer.className = <span class="literal">'sbUnitsContainer'</span>;
    <span class="reserved">this</span>.labelContainer.style.position = <span class="literal">'absolute'</span>;
    <span class="reserved">this</span>.graphicsContainer = document.createElement(<span class="literal">'div'</span>);
    <span class="reserved">this</span>.graphicsContainer.style.position = <span class="literal">'absolute'</span>;
    <span class="reserved">this</span>.graphicsContainer.className = <span class="literal">'sbGraphicsContainer'</span>;
    <span class="reserved">this</span>.numbersContainer = document.createElement(<span class="literal">'div'</span>);
    <span class="reserved">this</span>.numbersContainer.style.position = <span class="literal">'absolute'</span>;
    <span class="reserved">this</span>.numbersContainer.className = <span class="literal">'sbNumbersContainer'</span>;
    <span class="comment">// private functions</span>
    <span class="comment">// put in some markers and bar pieces so style attributes can be grabbed</span>
    <span class="comment">// this is a solution for Safari support</span>
    var markerMajor = document.createElement(<span class="literal">'div'</span>);
    markerMajor.className = <span class="literal">'sbMarkerMajor'</span>;
    <span class="reserved">this</span>.graphicsContainer.appendChild(markerMajor);
    var markerMinor = document.createElement(<span class="literal">'div'</span>);
    markerMinor.className = <span class="literal">'sbMarkerMinor'</span>;
    <span class="reserved">this</span>.graphicsContainer.appendChild(markerMinor);
    var barPiece = document.createElement(<span class="literal">'div'</span>);
    barPiece.className = <span class="literal">'sbBar'</span>;
    <span class="reserved">this</span>.graphicsContainer.appendChild(barPiece);
    var barPieceAlt = document.createElement(<span class="literal">'div'</span>);
    barPieceAlt.className = <span class="literal">'sbBarAlt'</span>;
    <span class="reserved">this</span>.graphicsContainer.appendChild(barPieceAlt);
}
ScaleBar.<span class="reserved">prototype</span>.update = <span class="reserved">function</span>(scaleDenominator) {
    <span class="reserved">if</span>(scaleDenominator != null) {
        <span class="reserved">this</span>.scaleDenominator = scaleDenominator;
    }
    <span class="comment">// local functions (and object constructors)</span>
    <span class="reserved">function</span> HandsomeNumber(smallUglyNumber, bigUglyNumber, sigFigs) {
        var sigFigs = (sigFigs == null) ? 10 : sigFigs;
        var bestScore = Number.POSITIVE_INFINITY;
        var bestTieBreaker = Number.POSITIVE_INFINITY;
        <span class="comment">// if all else fails, return a small ugly number</span>
        var handsomeValue = smallUglyNumber;
        var handsomeNumDec = 3;
        <span class="comment">// try the first three comely multiplicands (in order of comliness)</span>
        <span class="reserved">for</span>(var halvingExp = 0; halvingExp &lt; 3; ++halvingExp) {
            var comelyMultiplicand = Math.pow(2, (-1 * halvingExp));
            var maxTensExp = Math.floor(Math.log(bigUglyNumber / comelyMultiplicand) / Math.LN10)
            <span class="reserved">for</span>(var tensExp = maxTensExp; tensExp &gt; (maxTensExp - sigFigs + 1); --tensExp) {
                var numDec = Math.max(halvingExp - tensExp, 0);
                var testMultiplicand = comelyMultiplicand * Math.pow(10, tensExp);
                <span class="comment">// check if there is an integer multiple of testMultiplicand between smallUglyNumber and bigUglyNumber</span>
                <span class="reserved">if</span>((testMultiplicand * Math.floor(bigUglyNumber / testMultiplicand)) &gt;= smallUglyNumber) {
                    <span class="comment">// check if smallUglyNumber is an integer multiple of testMultiplicand</span>
                    <span class="reserved">if</span>(smallUglyNumber % testMultiplicand == 0) {
                        var testMultiplier = smallUglyNumber / testMultiplicand;
                    }
                    <span class="comment">// otherwise go for the smallest integer multiple between small and big</span>
                    <span class="reserved">else</span> {
                        var testMultiplier = Math.floor(smallUglyNumber / testMultiplicand) + 1;
                    }
                    <span class="comment">// test against the best (lower == better)</span>
                    var testScore = testMultiplier + (2 * halvingExp);
                    var testTieBreaker = (tensExp &lt; 0) ? (Math.abs(tensExp) + 1) : tensExp;
                    <span class="reserved">if</span>((testScore &lt; bestScore) || ((testScore == bestScore) &amp;&amp; (testTieBreaker &lt; bestTieBreaker))) {
                        bestScore = testScore;
                        bestTieBreaker = testTieBreaker;
                        handsomeValue = (testMultiplicand * testMultiplier).toFixed(numDec);
                        handsomeNumDec = numDec;
                    }
                }
            }
        }
        <span class="reserved">this</span>.value = handsomeValue;
        <span class="reserved">this</span>.score = bestScore;
        <span class="reserved">this</span>.tieBreaker = bestTieBreaker;
        <span class="reserved">this</span>.numDec = handsomeNumDec;
    }
    HandsomeNumber.<span class="reserved">prototype</span>.toString = <span class="reserved">function</span>() {
        <span class="reserved">return</span> <span class="reserved">this</span>.value.toString();
    }
    HandsomeNumber.<span class="reserved">prototype</span>.valueOf = <span class="reserved">function</span>() {
        <span class="reserved">return</span> <span class="reserved">this</span>.value;
    }
    <span class="reserved">function</span> styleValue(aSelector, styleKey) {
        <span class="comment">// returns an integer value associated with a particular selector and key</span>
        <span class="comment">// given a stylesheet with .someSelector {border: 2px solid red}</span>
        <span class="comment">// styleValue('.someSelector', 'borderWidth') returns 2</span>
        var aValue = 0;
        <span class="reserved">if</span>(document.styleSheets) {
            <span class="reserved">for</span>(var sheetIndex = document.styleSheets.length - 1; sheetIndex &gt;= 0; --sheetIndex) {
                var aSheet = document.styleSheets[sheetIndex];
                <span class="reserved">if</span>(!aSheet.disabled) {
                    var allRules;
                    <span class="reserved">if</span>(typeof(aSheet.cssRules) == <span class="literal">'undefined'</span>) {
                        <span class="reserved">if</span>(typeof(aSheet.rules) == <span class="literal">'undefined'</span>) {
                            <span class="comment">// can't get rules, assume zero</span>
                            <span class="reserved">return</span> 0;
                        }
                        <span class="reserved">else</span> {
                            allRules = aSheet.rules;
                        }
                    }
                    <span class="reserved">else</span> {
                        allRules = aSheet.cssRules;
                    }
                    <span class="reserved">for</span>(var ruleIndex = 0; ruleIndex &lt; allRules.length; ++ruleIndex) {
                        var aRule = allRules[ruleIndex];
                        <span class="reserved">if</span>(aRule.selectorText &amp;&amp; (aRule.selectorText.toLowerCase() == aSelector.toLowerCase())) {
                            <span class="reserved">if</span>(aRule.style[styleKey] != <span class="literal">''</span>) {
                                aValue = parseInt(aRule.style[styleKey]);
                            }
                        }
                    }
                }
            }
        }
        <span class="comment">// if the styleKey was not found, the equivalent value is zero</span>
        <span class="reserved">return</span> aValue ? aValue : 0;
    }
    <span class="reserved">function</span> formatNumber(aNumber, numDecimals) {
        numDecimals = (numDecimals) ? numDecimals : 0;
        var formattedInteger = <span class="literal">''</span> + Math.round(aNumber);
        var thousandsPattern = /(-?[0-9]+)([0-9]{3})/;
        <span class="reserved">while</span>(thousandsPattern.test(formattedInteger)) {
            formattedInteger = formattedInteger.replace(thousandsPattern, <span class="literal">'$1,$2'</span>);
        }
        <span class="reserved">if</span>(numDecimals &gt; 0) {
            var formattedDecimal = Math.floor(Math.pow(10, numDecimals) * (aNumber - Math.round(aNumber)));
            <span class="reserved">if</span>(formattedDecimal == 0) {
                <span class="reserved">return</span> formattedInteger;
            }
            <span class="reserved">else</span> {
                <span class="reserved">return</span> formattedInteger + <span class="literal">'.'</span> + formattedDecimal;
            }
        }
        <span class="reserved">else</span> {
            <span class="reserved">return</span> formattedInteger;
        }
    }
    <span class="comment">// update the container title (for displaying scale as a tooltip)</span>
    <span class="reserved">this</span>.container.title = <span class="literal">'scale 1:'</span> + formatNumber(<span class="reserved">this</span>.scaleDenominator);
    <span class="comment">// measurementProperties holds display units, abbreviations,</span>
    <span class="comment">// and conversion to inches (since we're using dpi) - per measurement sytem</span>
    var measurementProperties = new Object();
    measurementProperties.english = {
        units: [<span class="literal">'miles'</span>, <span class="literal">'feet'</span>, <span class="literal">'inches'</span>],
        abbr: [<span class="literal">'mi'</span>, <span class="literal">'ft'</span>, <span class="literal">'in'</span>],
        inches: [63360, 12, 1]
    }
    measurementProperties.metric = {
        units: [<span class="literal">'kilometers'</span>, <span class="literal">'meters'</span>, <span class="literal">'centimeters'</span>],
        abbr: [<span class="literal">'km'</span>, <span class="literal">'m'</span>, <span class="literal">'cm'</span>],
        inches: [39370.07874, 39.370079, 0.393701]
    }
    <span class="comment">// check each measurement unit in the display system</span>
    var comparisonArray = new Array();
    <span class="reserved">for</span>(var unitIndex = 0; unitIndex &lt; measurementProperties[<span class="reserved">this</span>.displaySystem].units.length; ++unitIndex) {
        comparisonArray[unitIndex] = new Object();
        var pixelsPerDisplayUnit = <span class="reserved">this</span>.resolution * measurementProperties[<span class="reserved">this</span>.displaySystem].inches[unitIndex] / <span class="reserved">this</span>.scaleDenominator;
        var minSDDisplayLength = (<span class="reserved">this</span>.minWidth / pixelsPerDisplayUnit) / (<span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions);
        var maxSDDisplayLength = (<span class="reserved">this</span>.maxWidth / pixelsPerDisplayUnit) / (<span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions);
        <span class="comment">// add up scores for each marker (even if numbers aren't displayed)</span>
        <span class="reserved">for</span>(var valueIndex = 0; valueIndex &lt; (<span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions); ++valueIndex) {
            var minNumber = minSDDisplayLength * (valueIndex + 1);
            var maxNumber = maxSDDisplayLength * (valueIndex + 1);
            var niceNumber = new HandsomeNumber(minNumber, maxNumber);
            comparisonArray[unitIndex][valueIndex] = {value: (niceNumber.value / (valueIndex + 1)), score: 0, tieBreaker: 0, numDec: 0, displayed: 0};
            <span class="comment">// now tally up scores for all values given this subdivision length</span>
            <span class="reserved">for</span>(var valueIndex2 = 0; valueIndex2 &lt; (<span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions); ++valueIndex2) {
                displayedValuePosition = niceNumber.value * (valueIndex2 + 1) / (valueIndex + 1);
                niceNumber2 = new HandsomeNumber(displayedValuePosition, displayedValuePosition);
                var isMajorMeasurement = ((valueIndex2 + 1) % <span class="reserved">this</span>.subdivisions == 0);
                var isLastMeasurement = ((valueIndex2 + 1) == (<span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions));
                <span class="reserved">if</span>((<span class="reserved">this</span>.singleLine &amp;&amp; isLastMeasurement) || (!<span class="reserved">this</span>.singleLine &amp;&amp; (isMajorMeasurement || <span class="reserved">this</span>.showMinorMeasures))) {
                    <span class="comment">// count scores for displayed marker measurements</span>
                    comparisonArray[unitIndex][valueIndex].score += niceNumber2.score;
                    comparisonArray[unitIndex][valueIndex].tieBreaker += niceNumber2.tieBreaker;
                    comparisonArray[unitIndex][valueIndex].numDec = Math.max(comparisonArray[unitIndex][valueIndex].numDec, niceNumber2.numDec);
                    comparisonArray[unitIndex][valueIndex].displayed += 1;
                }
                <span class="reserved">else</span> {
                    <span class="comment">// count scores for non-displayed marker measurements</span>
                    comparisonArray[unitIndex][valueIndex].score += niceNumber2.score / <span class="reserved">this</span>.subdivisions;
                    comparisonArray[unitIndex][valueIndex].tieBreaker += niceNumber2.tieBreaker / <span class="reserved">this</span>.subdivisions;
                }
            }
            <span class="comment">// adjust scores so numbers closer to 1 are preferred for display</span>
            var scoreAdjustment = (unitIndex + 1) * comparisonArray[unitIndex][valueIndex].tieBreaker / comparisonArray[unitIndex][valueIndex].displayed;
            comparisonArray[unitIndex][valueIndex].score *= scoreAdjustment;
        }
    }
    <span class="comment">// get the value (subdivision length) with the lowest cumulative score</span>
    var subdivisionDisplayLength = null;
    var displayUnits = null;
    var displayUnitsAbbr = null;
    var subdivisionPixelLength = null;
    var bestScore = Number.POSITIVE_INFINITY;
    var bestTieBreaker = Number.POSITIVE_INFINITY;
    var numDec = 0;
    <span class="reserved">for</span>(var unitIndex = 0; unitIndex &lt; comparisonArray.length; ++unitIndex) {
        <span class="reserved">for</span>(valueIndex in comparisonArray[unitIndex]) {
            <span class="reserved">if</span>((comparisonArray[unitIndex][valueIndex].score &lt; bestScore) || ((comparisonArray[unitIndex][valueIndex].score == bestScore) &amp;&amp; (comparisonArray[unitIndex][valueIndex].tieBreaker &lt; bestTieBreaker))) {
                bestScore = comparisonArray[unitIndex][valueIndex].score;
                bestTieBreaker = comparisonArray[unitIndex][valueIndex].tieBreaker;
                subdivisionDisplayLength = comparisonArray[unitIndex][valueIndex].value;
                numDec = comparisonArray[unitIndex][valueIndex].numDec;
                displayUnits = measurementProperties[<span class="reserved">this</span>.displaySystem].units[unitIndex];
                displayUnitsAbbr = measurementProperties[<span class="reserved">this</span>.displaySystem].abbr[unitIndex];
                pixelsPerDisplayUnit = <span class="reserved">this</span>.resolution * measurementProperties[<span class="reserved">this</span>.displaySystem].inches[unitIndex] / <span class="reserved">this</span>.scaleDenominator;
                subdivisionPixelLength = pixelsPerDisplayUnit * subdivisionDisplayLength; <span class="comment">// round before use in style</span>
            }
        }
    }
    <span class="comment">// determine offsets for graphic elements</span>
    var xOffsetMarkerMajor = (styleValue(<span class="literal">'.sbMarkerMajor'</span>, <span class="literal">'borderLeftWidth'</span>) + styleValue(<span class="literal">'.sbMarkerMajor'</span>, <span class="literal">'width'</span>) + styleValue(<span class="literal">'.sbMarkerMajor'</span>, <span class="literal">'borderRightWidth'</span>)) / 2;
    var xOffsetMarkerMinor = (styleValue(<span class="literal">'.sbMarkerMinor'</span>, <span class="literal">'borderLeftWidth'</span>) + styleValue(<span class="literal">'.sbMarkerMinor'</span>, <span class="literal">'width'</span>) + styleValue(<span class="literal">'.sbMarkerMinor'</span>, <span class="literal">'borderRightWidth'</span>)) / 2;
    var xOffsetBar = (styleValue(<span class="literal">'.sbBar'</span>, <span class="literal">'borderLeftWidth'</span>) + styleValue(<span class="literal">'.sbBar'</span>, <span class="literal">'borderRightWidth'</span>)) / 2;
    var xOffsetBarAlt = (styleValue(<span class="literal">'.sbBarAlt'</span>, <span class="literal">'borderLeftWidth'</span>) + styleValue(<span class="literal">'.sbBarAlt'</span>, <span class="literal">'borderRightWidth'</span>)) / 2;
    <span class="comment">// support for browsers without the Document.styleSheets property (Opera)</span>
    <span class="reserved">if</span>(!document.styleSheets) {
        <span class="comment">// this is a two part hack, one for the offsets here and one for the css below</span>
        xOffsetMarkerMajor = 0.5;
        xOffsetMarkerMinor = 0.5;
    }
    <span class="comment">// clean out any old content from containers</span>
    <span class="reserved">while</span>(<span class="reserved">this</span>.labelContainer.hasChildNodes()) {
        <span class="reserved">this</span>.labelContainer.removeChild(<span class="reserved">this</span>.labelContainer.firstChild);
    }
    <span class="reserved">while</span>(<span class="reserved">this</span>.graphicsContainer.hasChildNodes()) {
        <span class="reserved">this</span>.graphicsContainer.removeChild(<span class="reserved">this</span>.graphicsContainer.firstChild);
    }
    <span class="reserved">while</span>(<span class="reserved">this</span>.numbersContainer.hasChildNodes()) {
        <span class="reserved">this</span>.numbersContainer.removeChild(<span class="reserved">this</span>.numbersContainer.firstChild);
    }
    <span class="comment">// create all divisions</span>
    var aMarker, aBarPiece, numbersBox, xOffset;
    var alignmentOffset = {
        left: 0,
        center: (-1 * <span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions * subdivisionPixelLength / 2),
        right: (-1 * <span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions * subdivisionPixelLength)
    }
    var xPosition = 0 + alignmentOffset[<span class="reserved">this</span>.align];
    var markerMeasure = 0;
    <span class="reserved">for</span>(var divisionIndex = 0; divisionIndex &lt; <span class="reserved">this</span>.divisions; ++divisionIndex) {
        <span class="comment">// set xPosition and markerMeasure to start of division</span>
        xPosition = divisionIndex * <span class="reserved">this</span>.subdivisions * subdivisionPixelLength;
        xPosition += alignmentOffset[<span class="reserved">this</span>.align];
        markerMeasure = (divisionIndex == 0) ? 0 : ((divisionIndex * <span class="reserved">this</span>.subdivisions) * subdivisionDisplayLength).toFixed(numDec);
        <span class="comment">// add major marker</span>
        aMarker = document.createElement(<span class="literal">'div'</span>);
        aMarker.className = <span class="literal">'sbMarkerMajor'</span>;
        aMarker.style.position = <span class="literal">'absolute'</span>;
        aMarker.style.overflow = <span class="literal">'hidden'</span>;
        aMarker.style.left = Math.round(xPosition - xOffsetMarkerMajor) + <span class="literal">'px'</span>;
        aMarker.appendChild(document.createTextNode(<span class="literal">' '</span>));
        <span class="reserved">this</span>.graphicsContainer.appendChild(aMarker);
        <span class="comment">// add initial measure</span>
        <span class="reserved">if</span>(!<span class="reserved">this</span>.singleLine) {
            numbersBox = document.createElement(<span class="literal">'div'</span>);
            numbersBox.className = <span class="literal">'sbNumbersBox'</span>;
            numbersBox.style.position = <span class="literal">'absolute'</span>;
            numbersBox.style.overflow = <span class="literal">'hidden'</span>;
            numbersBox.style.textAlign = <span class="literal">'center'</span>;
            <span class="reserved">if</span>(<span class="reserved">this</span>.showMinorMeasures) {
                numbersBox.style.width = Math.round(subdivisionPixelLength * 2) + <span class="literal">'px'</span>;
                numbersBox.style.left = Math.round(xPosition - subdivisionPixelLength) + <span class="literal">'px'</span>;
            }
            <span class="reserved">else</span> {
                numbersBox.style.width = Math.round(<span class="reserved">this</span>.subdivisions * subdivisionPixelLength * 2) + <span class="literal">'px'</span>;
                numbersBox.style.left = Math.round(xPosition - (<span class="reserved">this</span>.subdivisions * subdivisionPixelLength)) + <span class="literal">'px'</span>;
            }
            numbersBox.appendChild(document.createTextNode(markerMeasure));
            <span class="reserved">this</span>.numbersContainer.appendChild(numbersBox);
        }
        <span class="comment">// create all subdivisions</span>
        <span class="reserved">for</span>(var subdivisionIndex = 0; subdivisionIndex &lt; <span class="reserved">this</span>.subdivisions; ++subdivisionIndex) {
            aBarPiece = document.createElement(<span class="literal">'div'</span>);
            aBarPiece.style.position = <span class="literal">'absolute'</span>;
            aBarPiece.style.overflow = <span class="literal">'hidden'</span>;
            aBarPiece.style.width = Math.round(subdivisionPixelLength) + <span class="literal">'px'</span>;
            <span class="reserved">if</span>((subdivisionIndex % 2) == 0) {
                aBarPiece.className = <span class="literal">'sbBar'</span>;
                aBarPiece.style.left = Math.round(xPosition - xOffsetBar) + <span class="literal">'px'</span>;
            }
            <span class="reserved">else</span> {
                aBarPiece.className = <span class="literal">'sbBarAlt'</span>;
                aBarPiece.style.left = Math.round(xPosition - xOffsetBarAlt) + <span class="literal">'px'</span>;
            }
            aBarPiece.appendChild(document.createTextNode(<span class="literal">' '</span>));
            <span class="reserved">this</span>.graphicsContainer.appendChild(aBarPiece);
            <span class="comment">// add minor marker if not the last subdivision</span>
            <span class="reserved">if</span>(subdivisionIndex &lt; (<span class="reserved">this</span>.subdivisions - 1)) {
                <span class="comment">// set xPosition and markerMeasure to end of subdivision</span>
                xPosition = ((divisionIndex * <span class="reserved">this</span>.subdivisions) + (subdivisionIndex + 1)) * subdivisionPixelLength;
                xPosition += alignmentOffset[<span class="reserved">this</span>.align];
                markerMeasure = (divisionIndex * <span class="reserved">this</span>.subdivisions + subdivisionIndex + 1) * subdivisionDisplayLength;
                aMarker = document.createElement(<span class="literal">'div'</span>);
                aMarker.className = <span class="literal">'sbMarkerMinor'</span>;
                aMarker.style.position = <span class="literal">'absolute'</span>;
                aMarker.style.overflow = <span class="literal">'hidden'</span>;
                aMarker.style.left = Math.round(xPosition - xOffsetMarkerMinor) + <span class="literal">'px'</span>;
                aMarker.appendChild(document.createTextNode(<span class="literal">' '</span>));
                <span class="reserved">this</span>.graphicsContainer.appendChild(aMarker);
                <span class="reserved">if</span>(<span class="reserved">this</span>.showMinorMeasures &amp;&amp; !<span class="reserved">this</span>.singleLine) {
                    <span class="comment">// add corresponding measure</span>
                    numbersBox = document.createElement(<span class="literal">'div'</span>);
                    numbersBox.className = <span class="literal">'sbNumbersBox'</span>;
                    numbersBox.style.position = <span class="literal">'absolute'</span>;
                    numbersBox.style.overflow = <span class="literal">'hidden'</span>;
                    numbersBox.style.textAlign = <span class="literal">'center'</span>;
                    numbersBox.style.width = Math.round(subdivisionPixelLength * 2) + <span class="literal">'px'</span>;
                    numbersBox.style.left = Math.round(xPosition - subdivisionPixelLength) + <span class="literal">'px'</span>;
                    numbersBox.appendChild(document.createTextNode(markerMeasure));
                    <span class="reserved">this</span>.numbersContainer.appendChild(numbersBox);
                }
            }
        }
    }
    <span class="comment">// set xPosition and markerMeasure to end of divisions</span>
    xPosition = (<span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions) * subdivisionPixelLength;
    xPosition += alignmentOffset[<span class="reserved">this</span>.align];
    markerMeasure = ((<span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions) * subdivisionDisplayLength).toFixed(numDec);
    <span class="comment">// add the final major marker</span>
    aMarker = document.createElement(<span class="literal">'div'</span>);
    aMarker.className = <span class="literal">'sbMarkerMajor'</span>;
    aMarker.style.position = <span class="literal">'absolute'</span>;
    aMarker.style.overflow = <span class="literal">'hidden'</span>;
    aMarker.style.left = Math.round(xPosition - xOffsetMarkerMajor) + <span class="literal">'px'</span>;
    aMarker.appendChild(document.createTextNode(<span class="literal">' '</span>));
    <span class="reserved">this</span>.graphicsContainer.appendChild(aMarker);
    <span class="comment">// add final measure</span>
    <span class="reserved">if</span>(!<span class="reserved">this</span>.singleLine) {
        numbersBox = document.createElement(<span class="literal">'div'</span>);
        numbersBox.className = <span class="literal">'sbNumbersBox'</span>;
        numbersBox.style.position = <span class="literal">'absolute'</span>;
        numbersBox.style.overflow = <span class="literal">'hidden'</span>;
        numbersBox.style.textAlign = <span class="literal">'center'</span>;
        <span class="reserved">if</span>(<span class="reserved">this</span>.showMinorMeasures) {
            numbersBox.style.width = Math.round(subdivisionPixelLength * 2) + <span class="literal">'px'</span>;
            numbersBox.style.left = Math.round(xPosition - subdivisionPixelLength) + <span class="literal">'px'</span>;
        }
        <span class="reserved">else</span> {
            numbersBox.style.width = Math.round(<span class="reserved">this</span>.subdivisions * subdivisionPixelLength * 2) + <span class="literal">'px'</span>;
            numbersBox.style.left = Math.round(xPosition - (<span class="reserved">this</span>.subdivisions * subdivisionPixelLength)) + <span class="literal">'px'</span>;
        }
        numbersBox.appendChild(document.createTextNode(markerMeasure));
        <span class="reserved">this</span>.numbersContainer.appendChild(numbersBox);
    }
    <span class="comment">// add content to the label container</span>
    var labelBox = document.createElement(<span class="literal">'div'</span>);
    labelBox.style.position = <span class="literal">'absolute'</span>;
    var labelText;
    <span class="reserved">if</span>(<span class="reserved">this</span>.singleLine) {
        labelText = markerMeasure;
        labelBox.className = <span class="literal">'sbLabelBoxSingleLine'</span>;
        labelBox.style.top = <span class="literal">'-0.6em'</span>;
        labelBox.style.left = (xPosition + 10) + <span class="literal">'px'</span>;
    }
    <span class="reserved">else</span> {
        labelText = <span class="literal">''</span>;
        labelBox.className = <span class="literal">'sbLabelBox'</span>;
        labelBox.style.textAlign = <span class="literal">'center'</span>;
        labelBox.style.width = Math.round(<span class="reserved">this</span>.divisions * <span class="reserved">this</span>.subdivisions * subdivisionPixelLength) + <span class="literal">'px'</span>
        labelBox.style.left = Math.round(alignmentOffset[<span class="reserved">this</span>.align]) + <span class="literal">'px'</span>;
        labelBox.style.overflow = <span class="literal">'hidden'</span>;
    }
    <span class="reserved">if</span>(<span class="reserved">this</span>.abbreviateLabel) {
        labelText += <span class="literal">' '</span> + displayUnitsAbbr;
    }
    <span class="reserved">else</span> {
        labelText += <span class="literal">' '</span> + displayUnits;
    }
    labelBox.appendChild(document.createTextNode(labelText));
    <span class="reserved">this</span>.labelContainer.appendChild(labelBox);
    <span class="comment">// support for browsers without the Document.styleSheets property (Opera)</span>
    <span class="reserved">if</span>(!document.styleSheets) {
        <span class="comment">// override custom css with default</span>
        var defaultStyle = document.createElement(<span class="literal">'style'</span>);
        defaultStyle.type = <span class="literal">'text/css'</span>;
        var styleText = <span class="literal">'.sbBar {top: 0px; background: #666666; height: 1px; border: 0;}'</span>;
        styleText += <span class="literal">'.sbBarAlt {top: 0px; background: #666666; height: 1px; border: 0;}'</span>;
        styleText += <span class="literal">'.sbMarkerMajor {height: 7px; width: 1px; background: #666666; border: 0;}'</span>;
        styleText += <span class="literal">'.sbMarkerMinor {height: 5px; width: 1px; background: #666666; border: 0;}'</span>;
        styleText += <span class="literal">'.sbLabelBox {top: -16px;}'</span>;
        styleText += <span class="literal">'.sbNumbersBox {top: 7px;}'</span>;
        defaultStyle.appendChild(document.createTextNode(styleText));
        document.getElementsByTagName(<span class="literal">'head'</span>).item(0).appendChild(defaultStyle);
    }
    <span class="comment">// append the child containers to the parent container</span>
    <span class="reserved">this</span>.container.appendChild(<span class="reserved">this</span>.graphicsContainer);
    <span class="reserved">this</span>.container.appendChild(<span class="reserved">this</span>.labelContainer);
    <span class="reserved">this</span>.container.appendChild(<span class="reserved">this</span>.numbersContainer);
}
ScaleBar.<span class="reserved">prototype</span>.place = <span class="reserved">function</span>(elementId) {
    <span class="reserved">if</span>(elementId == null) {
        document.body.appendChild(<span class="reserved">this</span>.container);
    }
    <span class="reserved">else</span> {
        var anElement = document.getElementById(elementId);
        <span class="reserved">if</span>(anElement != null) {
            anElement.appendChild(<span class="reserved">this</span>.container);
        }
    }
    <span class="reserved">this</span>.update();
}
</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b>ka-Map</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Wed Mar 15 10:50:59 2006</div>
</body>
</html>
